package com.tecode.myBooks.user.servlet;

import com.tecode.myBooks.user.bean.User;
import com.tecode.myBooks.user.service.UserService;
import com.tecode.myBooks.user.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

/**
 * Created by Administrator on 2018/11/21.
 */
@WebServlet("/userPhoneLogin")
public class UserPhoneLogin implements Servlet {
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {

    }

    @Override
    public ServletConfig getServletConfig() {
        return null;
    }

    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        //获得请求参数
        String phone =servletRequest.getParameter("phone");
            String code = servletRequest.getParameter("code");
            //封装对象
            User user = new User();
            user.setPhone(phone);
            user.setVeriCode(code);
        UserService userService = new UserServiceImpl();
        String result = userService.phoneLogin(user);

        servletResponse.setCharacterEncoding("UTF-8");
        servletResponse.setContentType("text/html");
        servletResponse.getWriter().print(result);
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    @Override
    public void destroy() {

    }
}
